// ==UserScript==
// @name         修改商品数量为999
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  自动将 product_num 改为 999
// @match        *://*.wegame.com.cn/*
// @match        *://*.wgame.gtimg.com/*
// @grant        none
// ==/UserScript==
(function () {
    'use strict';


    const isChildPage = location.href.includes('www.wegame.com.cn/pay-midas/goods.html');


        // ✅ 创建 UI 输入框
        function createUI() {
            const panel = document.createElement('div');
            panel.id = 'custom-buy-panel';
            panel.innerHTML = `
                <div style="
                    position: fixed;
                    bottom: 20px;
                    right: 20px;
                    background: #fff;
                    border: 1px solid #ccc;
                    padding: 10px;
                    z-index: 9999;
                    font-size: 14px;
                    border-radius: 6px;
                    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
                ">
                    <label>购买金额：</label>
                    <input type="number" id="productNumInput" value="" min="1" style="width: 60px;" />
                    <button id="saveBtn" style="margin-left: 10px;">保存</button>
                </div>
            `;
            document.body.appendChild(panel);

    
            document.getElementById('saveBtn').addEventListener('click', (e) => {
                localStorage.setItem('productNum', 1);
                // alert('保存成功！');
                const val =Number(document.getElementById('productNumInput').value)/10;
                if (!isNaN(val) && val > 0) {
                    localStorage.setItem('productNum', val);
                }
            });
        }

    let internalValue = null;

    Object.defineProperty(window, 'WeGamePay', {
        configurable: true,
        set(fn) {

            // 包装原始函数
            const wrapped = function (...args) {
                const [type, options] = args;
                if (type === 'product' && options && typeof options.productNum === 'number') {
                    console.log('原始productNum:', options.productNum);
                    let productNum= localStorage.getItem('productNum')
                    options.productNum = productNum;
                    console.log('修改后productNum:', options.productNum);
                }
                return fn.apply(this, args);
            };

            internalValue = wrapped;
        },
        get() {
            return internalValue;
        }
    });
    if (!isChildPage) {
        createUI() 
    }

})();